package com.cold.demo.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.cold.demo.web.service.UserService1;
import com.cold.demo.web.service.UserService2;
import com.cold.demo.web.service.UserService3;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author x c
 * @Email 378661553@qq.com
 * @Date Created in 2019/12/20 11:43
 */
@RestController
public class IndexController {

    @Autowired
    UserService1 userService1;

    @Autowired
    UserService2 userService2;

    @Resource
    @Qualifier("userService3_1")
    UserService3 userService3;

    @Resource
    UserService3 userService3_2;

    @PostConstruct
    public void init() {
        System.out.println(userService3);
    }


    @Bean
    public UserService3 userService3_1() {
        UserService3 userService3 = new UserService3();
        System.out.println("userService3_1____" + userService3);
        return userService3;
    }

    @Bean
    public UserService3 userService3_2() {
        UserService3 userService3 = new UserService3();
        System.out.println("userService3_2____" + userService3);
        return userService3;
    }

    @GetMapping("/index")
    public Object index(HttpServletRequest request, HttpServletResponse response, String param) {
        response.setCharacterEncoding("UTF-8");
        return new Person("哈哈",18);
    }

    @GetMapping("/index2")
    public Object index2(HttpServletRequest request,String param) {
        return JSONObject.parseObject(JSONObject.toJSONString(new Person("哈哈",18)));
    }
}
